package com.isdepci.project.factor.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.project.factor.domain.ProductInfo;
import com.isdepci.project.factor.service.IProductInfoService;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.web.page.TableDataInfo;

/**
 * 产品Controller
 *
 * @author isdepci
 * @date 2024-10-12
 */
@RestController
@RequestMapping("/factor/productInfo")
public class ProductInfoController extends BaseController {
    @Autowired
    private IProductInfoService productInfoService;

    /**
     * 查询产品列表
     */
    @PreAuthorize("@ss.hasPermi('factor:productInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductInfo productInfo) {
        startPage();
        List<ProductInfo> list = productInfoService.selectProductInfoList(productInfo);
        return getDataTable(list);
    }

    /**
     * 获取产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('factor:productInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(productInfoService.selectProductInfoById(id));
    }

    /**
     * 新增产品
     */
    @PreAuthorize("@ss.hasPermi('factor:productInfo:add')")
    @Log(title = "产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductInfo productInfo) {
        return (productInfoService.insertProductInfo(productInfo));
    }

    /**
     * 修改产品
     */
    @PreAuthorize("@ss.hasPermi('factor:productInfo:edit')")
    @Log(title = "产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductInfo productInfo) {
        return (productInfoService.updateProductInfo(productInfo));
    }

    /**
     * 删除产品
     */
    @PreAuthorize("@ss.hasPermi('factor:productInfo:remove')")
    @Log(title = "产品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(productInfoService.deleteProductInfoByIds(ids));
    }
}
